package com.dspsemi.wodi;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.GridView;
import android.widget.Toast;

import com.dspsemi.wodi.adapter.SeatsGridAdapter;
import com.dspsemi.wodi.entity.Seat;

public class RoomActivity extends Activity {

	private GridView seatsGrid;
	private SeatsGridAdapter adapter;
	private ArrayList<Seat> list_seats;

	private Button start;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_room);

		int total = getIntent().getIntExtra("people_total", 8);
		System.out.println("你丫进的是一个" + total + "人间");

		initViews();
		setListeners();
		initData();
	}

	private void initData() {
		list_seats.clear();

		Seat s1 = new Seat();
		s1.setNum("1");

		Seat s2 = new Seat();
		s2.setNum("2");

		Seat s3 = new Seat();
		s3.setNum("3");

		Seat s4 = new Seat();
		s4.setNum("4");

		list_seats.add(s1);
		list_seats.add(s2);
		list_seats.add(s3);
		list_seats.add(s4);

		adapter.notifyDataSetChanged();
	}

	private void initViews() {

		seatsGrid = (GridView) findViewById(R.id.seats);
		list_seats = new ArrayList<Seat>();
		adapter = new SeatsGridAdapter(this, list_seats);
		seatsGrid.setAdapter(adapter);

		start = (Button) findViewById(R.id.start);
	}

	private void setListeners() {

		start.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toast("不是房主不要点开始啊");
			}
		});

	}

	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {

		};
	};

	private void toast(String text) {
		Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
	}
}
